<?php
App::uses('AppHelper', 'View/Helper');
class AuthHelper extends AppHelper {
	
	public function Widget(){
		$panel = '';
		if(!$this->Session->check('Auth.User')){
			$panel = $this->WidgetNoUserLoggedIn();
		}else{
			$panel =$this->WidgetUserLoggedIn();
		}
		return $panel;
	}
	
	private function WidgetNoUserLoggedIn(){
		$panel = '<li>'.
				$this->Html->link(
							'<i class=\'icon-user\'></i> Connectez-vous',
							array(
								'controller' => 'users',
								'action' => 'login'
							),
							array('escape'=>false)
						).
				'</li>';

		return $panel;
	}
	
	private function WidgetUserLoggedIn(){
		$panel = '';
		
		$firstName = $this->Session->read('Auth.User.firstname');
		$lastName = $this->Session->read('Auth.User.lastname');
		
		$panel .= '<li class=\'dropdown\'>';
		$panel .= $this->Html->link(
							'<i class=\'icon-user\'></i>'.$firstName.' '.$lastName.' <i class="caret"></i>',
							'#',
							array('escape'=>false,
								'data-toggle'=>'dropdown',
								'class'=>'dropdown-toggle'
							)
						);
		$panel .= '<ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">';
		$panel .= '<li>';
		$panel .= $this->Html->link('Editez votre profil',
								array(
									'controller'=>'users',
									'action'=>'edit'
								)
							);
		$panel .= '</li>';
		$panel .= '<li>';
		$panel .= $this->Html->link('D&eacute;connectez-vous',
								array(
									'controller'=>'users',
									'action'=>'logout'
								),
								array('escape'=>false)
							);
		$panel .= '</li>';							
		$panel .= '</ul>';
		return $panel;
	}									
}
?>